library (swirl)
swirl ()
summary(afghan)
4.002
prop.table (province)
prop.table (afghan$province)
prop.table (table(afghan$province))
prop.table(table(afghan$province,afghan$employed))
sum (is.na (afghan$violent.exp.taliban))
x <- matrix (1:10, 2, 5)
x <- matrix (1:10, row=2, col=5, byrow = TRUE)
x <- matrix (1:10, nrow=2, ncol=5, byrow = TRUE)
mean(x$row)
mean (x)
rowMeans(x)
z
z [1,]
z [[1]]
z$z3
z[["z3"]]
8-2
10*
s
ssqrt(10)
sqrt(10)
0
infor()
info()
bye()
library (car)
install.packages("carData")
install.packages("carData")
library(car)
install.packages("carData")
install.packages("carData")
library(car)
prestige.dat <- data.frame (Prestige)
head (prestige.dat)
summary (prestige.dat)
plot (x = prestige.dat$income)
plot (x = prestige.dat$income, y = prestige.dat$prestige, main = "")
income.mod <- lm (prestige ~ income, data = prestige.dat)
abline (income.mod)
plot (x = prestige.dat$education, y = prestige.dat$prestige, main ="")
education.mod <- lm (prestige ~ education, data = prestige.dat)
abline (education.mod)
plot (education.mod)
mod <- lm (prestige ~ income + education, data = prestige.dat)
summary (mod)
library (texreg)
screenreg(mod)
screenreg (list(mod), stars = 0.05, digits = 2, custom.model.names = c("the first model"), custom.coef.names = c("Income", "Education", "Intercept"), reorder.coef = c(2,3,1))
htmlreg (list(mod), file = "tab_ml.doc", single.row = TRUE, stars = 0.05, digits = 2, custom.model.names = c(""), custom.coef.names = c ("Intercept", "Income", "Education"), reorder.coef = c(2,3,1))
coef (mod)
plotreg(list(mod),
# file = "/Users/johanneskarreth/Documents/Dropbox/Uni/Teaching/POS 517/Tutorials/Day 8 -
# Multiple regression/plot_m1.pdf",
custom.coef.names = c("Intercept", "Income", "Education"),
custom.model.names = c(""),
reorder.coef = c(2, 3, 1),
lwd.vbars = 0)
pres_mean <- mean (prestige.dat$prestige, na.rm = TRUE)
pres_mean
pres_mean <- mean(prestige.dat$prestige, na.rm = TRUE)
pres_sd <- sd(prestige.dat$prestige, na.rm = TRUE)
prestige.dat$prestige.std <- (prestige.dat$prestige - pres_mean) / pres_sd
inc_mean <- mean(prestige.dat$income, na.rm = TRUE)
inc_sd <- sd(prestige.dat$income, na.rm = TRUE)
prestige.dat$income.std <- (prestige.dat$income - inc_mean) / inc_sd
summary (prestige.dat)
educ_mean <- mean(prestige.dat$education, na.rm = TRUE)
educ_sd <- sd(prestige.dat$education, na.rm = TRUE)
prestige.dat$education.std <- (prestige.dat$education - educ_mean) / educ_sd
summary(prestige.dat)
mod.std <- lm(prestige.std ~ income.std + education.std, data = prestige.dat)
screenreg(list(mod.std),
stars = 0.05,
digits = 2,
custom.model.names = c(""),
custom.coef.names = c("Intercept", "Income", "Education"),
reorder.coef = c(2, 3, 1))
prestige.dat$prestige.std2 <- scale(prestige.dat$prestige)
prestige.dat$income.std2 <- scale(prestige.dat$income)
prestige.dat$education.std2 <- scale(prestige.dat$education)
summary(prestige.dat)
mod.std <- lm(scale(prestige) ~ scale(income) + scale(education), data = prestige.dat)
read.csv ("https://covid.ourworldindata.org/data/owid-covid-data.csv")
c<-read.csv ("https://covid.ourworldindata.org/data/owid-covid-data.csv")
View(c)
Europe <- c [c$location == "Europe"]
View(Europe)
Europe <- c [c$location == "World"]
Europe <- c [c$location == "Europe",]
View(Europe)
Europe <- c [c$location == "World",]
View(Europe)
View(Europe)
Europe <- c [c$continent == "Europe",]
View(Europe)
Europe <- c [c$continent == "Europe" & c$date == "2020-10-28",]
View(Europe)
China <- c[c$location == "China",]
View(China)
par(bg="yellow")
map ("worldHires", xlim=c(80, 120), ylim=c(0,25), col="#999999", fill=TRUE)
library (mapdata)
install.packages("map")
install.packages("MAP")
library (mapdata)
install.packages("mapdata")
install.packages
install.packages("mapdata")
library (mapdata)
install.packages("maps")
install.packages("maps")
install.packages("maps")
library (mapdata)
library (maps)
library (mapdata)
par(bg="yellow")
map ("worldHires", xlim=c(80, 120), ylim=c(0,25), col="blue", fill=TRUE)
par(bg="black")
par (bg="white")
map ("worldHires", xlim=c(80, 120), ylim=c(0,25), col="#999999", fill=TRUE)
map ("worldHires", xlim=c(-20, 100), ylim=c(0,80), col="#999999", fill=TRUE)
map ("worldHires", xlim=c(80, 120), ylim=c(0,25), col="blue", fill=TRUE)
thailand <- map ("worldHires", regions="Thailand", plot=FALSE, fill=TRUE)
map (thailand, col="blue",fill=TRUE, add=TRUE)
map ("worldHires", xlim=c(80, 120), ylim=c(0,25), col="blue", fill=TRUE)
map ("worldHires", xlim=c(-20, 100), ylim=c(0,80), col="#999999", fill=TRUE)
map ("worldHires", xlim=c(-5, 100), ylim=c(0,80), col="#999999", fill=TRUE)
map ("worldHires", xlim=c(-20, 100), ylim=c(20,80), col="#999999", fill=TRUE)
map ("worldHires", xlim=c(-20, 100), ylim=c(60,80), col="#999999", fill=TRUE)
map ("worldHires", xlim=c(-20, 100), ylim=c(20,80), col="#999999", fill=TRUE)
library(ggmap)
install.packages("ggmap")
library(maptools)
insinstall.packages("maptools")
install.packages("maptools")
install.packages("maptools")
library(maptools)
data(wrld_simpl)
plot(wrld_simpl)
View(wrld_simpl)
plot(wrld_simpl$NAME == "China")
rmarkdown::render_site()
install.packages("rmarkdown", type = "source")
install.packages("rmarkdown", type = "source")
library("rmarkdown")
name: "my-website"
navbar:
title: "My Website"
left:
- text: "Home"
href: index.html
- text: "About"
href: about.html
rmarkdown::render_site
rmarkdown::render_site
rmarkdown::render_site ()
rmarkdown::render_site
rmarkdown::render_site()
set.seed(1)
x1 <- rnorm (100)
x2 <- rnorm (100)
plot (x1, x2)
x1 <- rnorm (100)
x2 <- rnorm (100)
plot (x1, x2)
set.seed(1)
x1 <- rnorm (100)
x2 <- rnorm (100)
plot (x1, x2)
set.seed(1)
x1 <- rnorm (100)
x2 <- rnorm (100)
x1 <- rnorm (100)
x2 <- rnorm (100)
plot (x1, x2)
x1 <- rnorm (100)
x2 <- rnorm (100)
plot (x1, x2)
plot (x1, x2, pch = 16)
plot (x1, x2, pch = 10)
plot (x1, x2, pch = 10, type = 1)
plot (x1, x2, pch = 10, type = "1")
plot (x1, x2, pch = 10, type = "2")
plot (x1, x2, pch = 10, col = "red")
plot (x1, x2, pch = 10, col = "red", lwd = 3)
x2 <- seq (0, 2*pi, len = 100)
x2
y2 <- sin (x2)
plot (x2, y2, type = "1")
plot (x2, y2)
plot (x2, y2, col = "darkgreen", lwd = 3, ylim = c (-1.2,1.2))
plot (x2, y2, col = "darkgreen", lwd = 3, ylim = c (-1.2,1.2), xlim = c(0,7))
y2r <- y2 + rnorm (100, 0, 0.1)
b <- rnorm (100, 0, 0.1)
summary (b)
max(b)
plot (x2, y2r, col = "darkgreen", lwd = 3, ylim = c (-1.2,1.2), xlim = c(0,7))
?rnorm
points (x2, y2r)
plot (x2, y2, col = "darkgreen", lwd = 3, ylim = c (-1.2,1.2), xlim = c(0,7))
points (x2, y2r)
y4 <- cos(x2)
plot (x2, y2)
lines (x2, y4)
plot (x2, y2r, col = "darkgreen", lwd = 3, ylim = c (-1.2,1.2), xlim = c(0,7))
plot (x2, y2r, col = "darkgreen", lwd = 1, ylim = c (-1.2,1.2), xlim = c(0,7))
lines (x2, y2)
par (mfrow = c(1,2))
plot (x2, y2)
plot (x2, y2, col = "darkgreen", lwd = 1, ylim = c (-1.2,1.2), xlim = c(0,7))
points (x2, y2r)
lines (x2, y2r)
par (mfrow = c(1,1))
plot (x2, y2)
x2 <- seq (0, 2*pi)
?len
x2
x2 <- seq (0, 2*pi, len = 100)
x2
y2 <- sin (x2)
y4 <- cos (x2)
par (mfrow = c(1,2))
plot (y2, y4)
lines (y2, y4)
polygon(y2, y4)
polygon(y2, y4, col = "dark")
polygon(y2, y4, col = "blue")
plot (y2, y4, asp = 1, type = "n")
plot (y2, y4, asp = 1, type = "n")
plot (y2, y4, asp = 1, type = "n")
polygon(y2, y4, col = "blue")
plot (y2, y4, asp = 1, type = "n")
polygon(y2, y4, col = "blue")
plot (y2, y4, asp = 2, type = "n")
polygon(y2, y4, col = "blue")
install.packages("GISTools", depend = T)
library (GISTools)
install.packages("GISTools", depend = T)
install.packages("GISTools", depend = T)
library (GISTools)
install.packages("GISTools", depend = T)
install.packages("GISTools", depend = T)
library (GISTools)
install.packages("sp", depend = T)
install.packages("sp", depend = T)
install.packages("MASS")
library (MASS)
library (sp)
library (GISTools)
library (rgeos)
library (maptools)
library (GISTools)
data (China)
data (china)
data (japan)
data (us)
data ("georgia")
?GISTools
data ("georgia")
appling <- georgia.polys [[1]]
plot (appling)
plot (appling, asp = 1)
plot (appling, asp = 1, type = 'n')
polygon (appling)
View(georgia)
library (ggplot2)
df <- data.frame (georgia)
tb <- as.tibble (df)
library (gridExtra)
tb <- as.tibble (df)
171.88*50
193.05*50
186.65*50
74*0.15 + 68*0.25
28.1/0.4
library (NLP)
library (tm)
library (SnowballC)
library("tidyverse")
library (mtcars)
mtcars
library("tidyverse")
names 9mtcars)
names (mtcars)
mtcars <- mtcars %>% select (cyl, disp, hp)
View(mtcars)
mtcars <- mtcars %>% select (cyl, disp, hp)
mtcars <- mtcars %>% select (cyl, disp, hp)
%>% by_group (cyl)
%>% summarise(haha = disp/hp)
mtcars <- mtcars %>% select (cyl, disp, hp) %>%
by_group (cyl) %>%
summarise(haha = disp/hp)
mtcars <- mtcars %>% select (cyl, disp, hp) %>%
group_by (cyl) %>%
summarise(haha = disp/hp)
View(mtcars)
mtcars <- mtcars %>% select (cyl, disp, hp) %>%
group_by (cyl) %>%
summarise(haha = disp/hp) %>%
ungroup ()
mtcars <- mtcars %>% select (cyl, disp, hp) %>%
group_by (cyl) %>%
summarise(haha = disp/hp) %>%
ungroup ()
mtcars
mtcars <- mtcars %>% select (cyl, disp, hp) %>%
group_by (cyl) %>%
summarise(haha = disp/hp) %>%
ungroup ()
library("tidyverse")
1mtcars <- mtcars %>% select (cyl, disp, hp) %>%
group_by (cyl) %>%
summarise(haha = disp/hp) %>%
ungroup ()
1mtcars <- mtcars %>% select (cyl, disp, hp) %>%
group_by (cyl) %>%
summarise(haha = disp/hp) %>%
ungroup ()
mtcars
mtcarsd <- mtcars %>% select (cyl, disp, hp) %>%
group_by (cyl) %>%
summarise(haha = disp/hp) %>%
ungroup ()
View(mtcarsd)
mtcarsd <- mtcars %>% select (cyl, disp, hp) %>%
group_by (cyl) %>%
summarise(haha = sum (disp)) %>%
ungroup ()
View(mtcarsd)
mtcarsd <- mtcars %>% select (cyl, disp, hp) %>%
group_by (cyl) %>%
summarise(haha = disp/hp) %>%
ungroup ()
mtcarsd <- mtcars %>% select (cyl, disp, hp) %>%
group_by (cyl) %>%
mutate(haha = disp/hp) %>%
ungroup ()
mtcarsd <- mtcars %>% select (cyl, disp, hp) %>%
group_by (cyl) %>%
mutate(haha = sum (disp))
ggplot (mtcars, aes(cyl, haha)) + geom_bar()
mtcarsd <- mtcars %>% select (cyl, disp, hp) %>%
group_by (cyl) %>%
mutate(haha = sum (disp))
ggplot (mtcars, aes(cyl, haha)) + geom_bar()
View(mtcarsd)
mtcars
mtcarsd <- mtcars %>% select (cyl, disp, hp) %>%
group_by (cyl) %>%
summarise(haha = sum (disp))
ggplot (mtcars, aes(cyl, haha)) + geom_bar()
ggplot (mtcarsd, aes(cyl, haha)) + geom_bar()
ggplot (mtcarsd, aes(cyl, haha)) + geom_line()
mtcars
ggplot (mtcars, aes (mpg, cyl))
library(ggplot2)
ggplot (mtcars, aes (mpg, cyl))
ggplot (mtcars, aes (mpg, cyl), col = gear)
ggplot (mtcars, aes (mpg, cyl), col = gear) + geom_point()
ggplot (mtcars, aes (mpg, cyl), col = gear) + geom_line()
ggplot (mtcars, aes (mpg, cyl, fill = gear)) + geom_line()
ggplot (mtcars, aes (mpg, cyl, fill = gear)) + geom_line()
mtcars
ggplot (mtcars, aes (mpg, cyl, fill = am)) + geom_line()
ggplot (mtcars, aes (mpg, cyl, fill = am)) + geom_point()
ggplot (mtcars, aes (mpg, cyl, fill = gear)) + geom_point()
ggplot (mtcars, aes (mpg, cyl, color = gear)) + geom_point()
ggplot (mtcars, aes (mpg, cyl, color = fcyl)) + geom_point()
names (mtcars)
ggplot (mtcars, aes (mpg, cyl, color = cyl)) + geom_point()
EUK2010 <- readRDS("EU_Kids_Online_2010_Week2.rds")
setwd("/Users/zhaowangyin/Desktop/LSE/COURSES/MY451_Introduction to Quan/WEEK2"
setwd("/Users/zhaowangyin/Desktop/LSE/COURSES/MY451_Introduction to Quan/WEEK2")
setwd("/Users/zhaowangyin/Desktop/LSE/COURSES/MY451_Introduction to Quan/WEEK2")
setwd("/Users/zhaowangyin/Desktop/LSE/COURSES/MY451_Introduction to Quan/WEEK2")
setwd("/Users/zhaowangyin/Desktop/LSE/COURSES/MY451_Introduction to Quan/WEEK2")
setwd("/Users/zhaowangyin/Desktop/LSE/COURSES/MY451_Introduction to Quan/WEEK2")
setwd ("/Users/zhaowangyin/Desktop/LSE/COURSES/MY451_Introduction to Quan/WEEK2")
getwd()
setwd ("/Users/zhaowangyin/Desktop/LSE/COURSES/MY451_Introduction to Quan/WEEK2")
setwd("/Users/zhaowangyin/Desktop/LSE/COURSES/MY451_Introduction to Quan/WEEK2")
setwd("/Users/zhaowangyin/Desktop/LSE/COURSES/MY451_Introduction to Quan/WEEK3")
matrix(2,2)
matrix(2,2,2)
C<-matrix(2,2,2)
dim(C)
library (tidyverse)
c <- rnorm(100, 24, 10)
d <- rnorm(100, 30, 20)
c <- lm (d~c)
summary (c)
c <- rnorm(100, 24, 10)
d <- rnorm(100, 30, 20)
f <- lm (d~c)
summary (f)
abline (c)
plot (c,d)
abline (e)
abline (f)
x <- rnorm (100, 10, 10)
draws <- sample (x, size = )
sample(1:10, 3)
set.seed()
sample (8,3)
for (i in 1:1000){sample_means[i] <- mean(sample (8,3), replace = TRUE)}
set.seed(100)
sample_means <- c()
for (i in 1:1000){sample_means[i] <- mean(sample (8,3), replace = TRUE)}
sample_means
hist (sample_means)
for (i in 1:10000){sample_means[i] <- mean(sample (8,3), replace = TRUE)}
hist (sample_means)
set.seed(100)
sample_means <- c()
for (i in 1:1000000){sample_means[i] <- mean(sample (8,3), replace = TRUE)}
hist (sample_means)
c <- rnorm (100, 1, 2)
d <- rnorm (100, 2,10)
f<- lm(c~d)
summary (f)
library (foreign)
library(dplyr)
library(ggplot2)
library(ggpubr)
install.packages("ggpubr")
library(ggpubr)
library(stargazer)
library(RATest)
install.packages("RATest")
library(RATest)
library (gridExtra)
library(RATest)
set.seed(82732)
sim_data <- cbind(y0, y1, x1) %>% as_tibble()
set.seed(82732)
N <- 5000
x1 <- rnorm(N,mean=1,sd=2)
b0 <- 5
b1 <- 0.5
y0 <- b0 + b1*x1 + rnorm(N)
y1 <- y0 + mean(y0) + rnorm(N)
sim_data <- cbind(y0, y1, x1) %>% as_tibble()
plot_data <-
cbind(y = c(y0, y1), x1 = c(x1, x1)) %>% as_tibble() %>%
mutate(Counterfactual = c(rep('y0', N), rep('y1', N)),
d = c(rep(0, N), rep(1, N)))
p1 <- ggplot(data = plot_data, aes(x = x1, y = y, color = Counterfactual)) +
geom_point(alpha = .1) + geom_smooth(method = "lm", se = FALSE) +
guides(color = guide_legend(override.aes = list(alpha = 1)))
p2 <- ggplot(data = plot_data,
aes(y = y, x = Counterfactual, fill = Counterfactual)) +
geom_boxplot() + theme(legend.position = 'none')
p3 <- ggplot(data = plot_data, aes(x = y, fill = Counterfactual)) +
geom_density(alpha = .3)
ggarrange(p1, ggarrange(p2, p3, ncol = 2), nrow = 2)
78999 10 108
7+8+27+10+10+8
70*0.25
(70-27.5)/0.6
(70-27.5)/0.7
73-27.5
45.5/0.7
31.600 – 14.363
31.6 - 14.363
16.952 – 13.477
16.952 - 13.477
16.95 - 13.48
c <- rnorm (1,2,3)
c
c <- rnorm (1000,2,3)
c
mean (c)
sd (c)
d <- rnorm (1000,3,5)
a <- lm (c~d)
summary (a)
plot (c, d)
plot (d, c)
plot (d, c, type = line)
abline ()
plot (d, c)
abline ()
abline (a)
d <- rnorm (1000,5,5)
a <- lm (c~d)
plot (d, c)
e <- 1.75*c
a <- lm (c~ e + d)
plot (d, e)
plot (e, c)
a <- lm (c~ e + d)
summary (a)
plot (a)
a <- lm (c~ e + d + f)
f <- rnorm (1000, 19, 2)
a <- lm (c~ e + d + f)
summary (a)
plot (a)
install.packages("descr")
library (descr)
descr(c)
setwd ("/Users/zhaowangyin/Desktop/PHL_ADMIN/gadm41_PHL_shp")
library (sf)
library (tmap)
ph2 <- st_read("gadm41_PHL_2.shp")
setwd ("/Users/zhaowangyin/Desktop/PSGC/Municipalities")
mun <- st_read ("Municipalities.shp")
